---
category: Number
created: '2020-04-19'
title: Convert a string to number
updated: '2021-10-13'
---

**JavaScript version**

```js toNumber.js
const toNumber = (str) => +str;
```

**TypeScript version**

```ts toNumber.ts
const toNumber = (str: string): number => +str;
```

**Examples**

```js examples.js
toNumber('42'); // 42
```
